﻿using WindowsForms.AOnline.Model.BusinessObjects.Dictionary;
using WindowsForms.AOnline.Presenter.Dictionary.Account;
using WindowsForms.AOnline.View.Dictionary;
//using System.Threading.Tasks;

namespace WindowsForms.AOnline.Presenter.Dictionary.FixedAsset
{
    public class FixedAssetPresenter : Presenter<IFixedAssetView>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AccountPresenter" /> class.
        /// </summary>
        /// <param name="view">The view.</param>
        public FixedAssetPresenter(IFixedAssetView view)
            : base(view)
        {
        }

        /// <summary>
        /// Displays the specified employ identifier.
        /// </summary>
        /// <param name="fixedAssetId">The employ identifier.</param>
        public void Display(string fixedAssetId)
        {
            if (fixedAssetId == null) { View.FixedAssetId = 0; return; }
            var obj = Model.GetFixedAsset(int.Parse(fixedAssetId));
                View.FixedAssetId = obj.FixedAssetId;
                View.FixedAssetCode = obj.FixedAssetCode;
                View.FixedAssetName = obj.FixedAssetName;
                View.FixedAssetForeignName = obj.FixedAssetForeignName;
                View.FixedAssetCategoryId = (int)obj.FixedAssetCategoryId;
                View.State = obj.State;
                View.Description = obj.Description;
                View.ProductionYear = obj.ProductionYear;
                View.MadeIn = obj.MadeIn;
                View.PurchasedDate = obj.PurchasedDate;
                View.UsedDate = obj.UsedDate;
                View.DepreciationDate = obj.DepreciationDate;
                View.IncrementDate = obj.IncrementDate;
                View.DisposedDate = obj.DisposedDate;
                View.Unit = obj.Unit;
                View.SerialNumber = obj.SerialNumber;
                View.Accessories = obj.Accessories;
                View.Quantity = obj.Quantity;
                View.UnitPrice = obj.UnitPrice;
                View.OrgPrice = obj.OrgPrice;
                View.AccumDepreciationAmount = obj.AccumDepreciationAmount;
                View.RemainingAmount = obj.RemainingAmount;
                View.AnnualDepreciationAmount = obj.AnnualDepreciationAmount;
                View.LifeTime = obj.LifeTime;
                View.DepreciationRate = obj.DepreciationRate;
                View.OrgPriceAccountCode = obj.OrgPriceAccountCode;
                View.DepreciationAccountCode = obj.DepreciationAccountCode;
                View.CapitalAccountCode = obj.CapitalAccountCode;
                View.DepartmentId = (int)obj.DepartmentId;
                View.EmployeeId = obj.EmployeeId;
                View.IsActive = obj.IsActive;
                View.CapitalMoneyAccountCode = obj.CapitalMoneyAccountCode;
                View.ExpenseAccountCode = obj.ExpenseAccountCode;
                View.UnitId = obj.UnitId;
        }

        /// <summary>
        /// Saves this instance.
        /// </summary>
        /// <returns>System.Int32.</returns>
        public string Save()
        {
            var obj = new FixedAssetModel
            {
                FixedAssetId = View.FixedAssetId,
                FixedAssetCode = View.FixedAssetCode,
                FixedAssetName = View.FixedAssetName,
                FixedAssetCategoryId = View.FixedAssetCategoryId,
                State = View.State,
                Description = View.Description,
                ProductionYear = View.ProductionYear,
                MadeIn = View.MadeIn,
                PurchasedDate = View.PurchasedDate,
                UsedDate = View.UsedDate,
                DepreciationDate = View.DepreciationDate,
                IncrementDate = View.IncrementDate,
                DisposedDate = View.DisposedDate,
                Unit = View.Unit,
                SerialNumber = View.SerialNumber,
                Accessories = View.Accessories,
                Quantity = View.Quantity,
                UnitPrice = View.UnitPrice,
                OrgPrice = View.OrgPrice,
                AccumDepreciationAmount = View.AccumDepreciationAmount,
                RemainingAmount = View.RemainingAmount,
                AnnualDepreciationAmount = View.AnnualDepreciationAmount,
                LifeTime = View.LifeTime,
                DepreciationRate = View.DepreciationRate,
                OrgPriceAccountCode = View.OrgPriceAccountCode,
                DepreciationAccountCode = View.DepreciationAccountCode,
                CapitalAccountCode = View.CapitalAccountCode,
                DepartmentId = View.DepartmentId,
                EmployeeId = View.EmployeeId,
                IsActive = View.IsActive,
                CapitalMoneyAccountCode = View.CapitalMoneyAccountCode,
                ExpenseAccountCode = View.ExpenseAccountCode,
                UnitId = View.UnitId
            };
            //return View.FixedAssetId == 0 ? Model.AddFixedAsset(obj) : Model.UpdateFixedAsset(obj);
            if (View.FixedAssetId == 0)
                return Model.AddFixedAsset(obj);
            return Model.UpdateFixedAsset(obj);
        }

        /// <summary>
        /// Deletes the specified employ identifier.
        /// </summary>
        /// <param name="fixedAssetId">The employ identifier.</param>
        /// <returns>System.Int32.</returns>
        public string Delete(int fixedAssetId)
        {
            return Model.DeleteFixedAsset(fixedAssetId);
        }
    }
}
